# -*- coding: utf-8 -*-
# @Time : 2022/9/28 23:03
# @Author : zgj
# @File : FILE_PATH.py

import os

import pandas
import yaml

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

LOG_FILE_PATH = os.path.join(BASE_DIR, "logs") #日志文件路径

def read_excel(filepath,sheet_name):

    # keep_default_na 为false表示当你的单元格为空的时候，返回的是空字符串
    # engine表示选择的底层引擎是什么
    res = pandas.read_excel(BASE_DIR+filepath,sheet_name=sheet_name,keep_default_na=False,engine='openpyxl')
    # 需要将拿到的数据转换成列表套列表的形式
    data = [] # 总的数据存储
    lines_count = res.shape[0] # 表示从行数,不包括表头
    cols_count = res.shape[1] #表示总列数
    for l in range(lines_count):
        lines = []
        for c in range(cols_count):
            cell_data = res.iloc[l,c] #获取单元格数据
            lines.append(cell_data)#将单元格数据追加lines这个列表里
        # 遍历列完成后，当前行的数据都存在lines中了
        data.append(lines)
    return data


def load_yaml_file(filepath):
    with open(BASE_DIR+filepath,mode='r',encoding='UTF-8') as f:
        yaml_content = yaml.load(f,Loader=yaml.FullLoader)
        return yaml_content
def write_yaml(filepath,content):
    with open(BASE_DIR+filepath,mode='w',encoding='UTF-8') as f:
        yaml.dump(content,f,Dumper=yaml.Dumper)

def get_config_value(filepath,key):
    """
    从common.yml文件中获取指定键对应的配置值
    """
    with open(BASE_DIR+filepath, mode='r',encoding='UTF-8') as f:
        config_data = yaml.safe_load(f)
    return config_data.get(key)

if __name__ == '__main__':
    # print(load_yaml_file('/config/common.yml'))
    # content = {'token': '46B962D7E1E24E66B87BECA84918E6E6', 'admin_id': '374a2b4762b7938337af9ddec0a3218a',
    #  'chat_room_id': 133437, 'course_id': '1',
    #  'zuser_id': '1', 'versionName': '1'}
    # write_yaml('/config/common.yml',content)
    # print(load_yaml_file('/config/common.yml'))
    content = load_yaml_file('/config/common.yml')
    a = content['default_pop'].get('collect_course_info')
    print(a)


